package vfs.common.command;

import vfs.common.User;
import vfs.common.command.remote.RemoteCommand;
import vfs.common.file.VirtualFileSystem;
import vfs.common.tty.RemoteTty;

import java.io.Serializable;

/**
 * User: serge
 * Date: 19.11.13
 * Time: 4:53
 */
public abstract class AbstractCommand implements Serializable, Command, RemoteCommand
{
    protected String[] params;
    /** user called command */
    protected User user;
    protected VirtualFileSystem filesystem;
    protected RemoteTty tty;

    @Override
    public void setParams(String[] params)
    {
        this.params = params;
    }

    @Override
    public void setFilesystem(VirtualFileSystem filesystem)
    {
        this.filesystem = filesystem;
    }

    @Override
    public void setUser(User user)
    {
        this.user = user;
    }

    @Override
    public void setRemoteTty(RemoteTty tty)
    {
        this.tty = tty;
    }

    protected void checkUser()
    {
        if (user == null)
        {
            throw new IllegalStateException("User couldn't be null");
        }
    }

    protected void checkFilesystem()
    {
        if (filesystem == null)
        {
            throw new IllegalStateException("VFS couldn't be null");
        }
    }

    protected void checkTty()
    {
        if (tty == null)
        {
            throw new IllegalStateException("Broadcast tty couldn't be null");
        }
    }
}
